home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / printers / iprint / fullypth.c next >
Text File  |  1996-07-10  |  8KB  |  162 lines

  1. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  2. /* FullyPth : Get fully path of file.                                       */
  3. /* Author   : Marc Chauffour                                                */
  4. /* Written      : 02/16/90 09:24am                                          */
  5. /* Last_updated :                                                           */
  6. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  7. /* Use INT 21 - Function 60h                                                */
  8. /* Rem : Letters are uppercased, forward slashes converted to backslashes,  */
  9. /*       aterisks converted to appropriate number of question marks, and    */
  10. /*       file an directory names are truncated to 8.3 if necessary          */
  11. /*       '.' and '..' in the path are resolved                              */
  12. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  13. #include <dos.h>            /* DOS interrupt                    */
  14. #include <dir.h>
  15. #include <string.h>
  16. #include "fullypth.h"
  17. #define CAVAMAL -1            /* if problem */
  18.  
  19.  
  20.  
  21.  
  22. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  23. /* int getfullypath(char *,char *)                                          */
  24. /* returns : 0  - Ok                                                        */
  25. /*           02 - Invalid source name                                       */
  26. /*           03 - Invalid drive or malformed path                           */
  27. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  28. int getfullypath
  29.     (
  30.     char *fulypth,            /* resolved path                    */
  31.     char *pathin            /* path to resolve                  */
  32.     )
  33. {
  34. char drive[MAXDRIVE];            /* drive letter                     */
  35. char dir[MAXDIR];            /* Directory                        */
  36. char filename[MAXDIR];            /* Filename without extension       */
  37. char ext[MAXEXT];            /* Extension                        */
  38. char path[255];                /* working area                     */
  39. int drivenb;                /* drive number             */
  40. int driveprov;                /* Temporary drive */
  41.  
  42. union REGS regs;            /* Register                         */
  43. struct SREGS sregs;            /* segment register                 */
  44. int ret;                /* Return code                      */
  45.   strcpy(path,pathin);            /* save copy of path                */
  46.   fnsplit(path,drive,dir,filename,ext); /* look for drive and dir           */
  47.   drivenb = getdisk();        /* drive in use                     */
  48.   if (drive[0] != '\0')            /* no drive ?                   */
  49.     {
  50.     driveprov = drive[0] - 'A';        /* drive NOW in use                 */
  51.     setdisk(driveprov);            /* set new drive                    */
  52.     }
  53.   fnmerge(path,drive,dir,filename,ext);
  54.   regs.h.ah = 0x60;            /* resolve path string              */
  55.   sregs.ds = FP_SEG(path);        /* source path Segment              */
  56.   regs.x.si = FP_OFF(path);        /* source path Offset               */
  57.   sregs.es = FP_SEG(fulypth);        /* target path Segment              */
  58.   regs.x.di = FP_OFF(fulypth);        /* target path Offset               */
  59.   ret=intdosx(®s,®s,&sregs);      /* DOS interrupt with 60h           */
  60.   setdisk(drivenb);            /* Retrun correct drive             */
  61.   return( (regs.x.cflag!=0) ? ret : 0); /* Return code                      */
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  69. /* int getnovellpath(char *,char *)                                         */
  70. /* returns : 0  - Ok                                                        */
  71. /*         01 - Not a novell drive                                        */
  72. /*           02 - Invalid source name                                       */
  73. /*           03 - Invalid drive or malformed path                           */
  74. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  75. int getnovellpath
  76.     (
  77.     char *fulypth,            /* resolved path                    */
  78.     char *path                /* path to resolve                  */
  79.     )
  80. {
  81. int ret;                /* return code                      */
  82. int i,j;                /* counter                          */
  83.    ret=getfullypath(fulypth,path);    /* standard path                    */
  84.    if (ret!=0) return(ret);        /* problem                          */
  85.    if (fulypth[1]!='\\') return(1);    /* if "\\servername\volume\path\.." */
  86.    for(i=0,j=2;fulypth[j]!='\\';)
  87.      fulypth[i++]=fulypth[j++];         /* copy Server name                 */
  88.    fulypth[i++]='/';            /* separator */
  89.    for(j++;fulypth[j]!='\\';)
  90.      fulypth[i++]=fulypth[j++];         /* copy volume name                 */
  91.    fulypth[i++]=':';            /* separator                        */
  92.    for(j++;fulypth[j]!='\0';)
  93.      fulypth[i++]=fulypth[j++];         /* copy path                        */
  94.    fulypth[i]='\0';
  95.    return(0);                /* no problem                       */
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  103. /* int getdrivepath(char *,char *)                                          */
  104. /* returns : 0  - Ok                                                        */
  105. /*           02 - Invalid source name                                       */
  106. /*           03 - Invalid drive or malformed path                           */
  107. /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  108. int getdrivepath
  109.     (
  110.     char *fulypth,            /* resolved path                    */
  111.     char *pathin            /* path to resolve                  */
  112.     )
  113. {
  114. char drive[MAXDRIVE];            /* drive letter                     */
  115. char dir[MAXDIR];            /* Directory                        */
  116. char filename[MAXDIR];            /* Filename without extension       */
  117. char ext[MAXEXT];            /* Extension                        */
  118. char path[255];
  119.  
  120. int drivenb;                /* drive number             */
  121. int driveprov;                /* drive provisoire                 */
  122. int i,j;
  123.  
  124. union REGS regs;            /* Register                         */
  125. struct SREGS sregs;            /* segment register                 */
  126. int ret;                /* Return code                      */
  127.  
  128.   strcpy(path,strupr(pathin));
  129.   fnsplit(path,drive,dir,filename,ext); /* look for drive and dir           */
  130.   drivenb = getdisk();        /* drive in use                     */
  131.   if (drive[0] != '\0')            /* no drive ?                   */
  132.     {
  133.     driveprov = drive[0] - 'A';        /* drive NOW in use                 */
  134.     setdisk(driveprov);            /* set new drive                    */
  135.     }
  136.   else
  137.     {
  138.     drive[0]=drivenb + 'A';
  139.     drive[1]=':';
  140.     drive[2]='\0';
  141.     }
  142.   fnmerge(path,drive,dir,filename,ext);
  143.   regs.h.ah = 0x60;            /* resolve path string              */
  144.   sregs.ds = FP_SEG(path);        /* source path Segment              */
  145.   regs.x.si = FP_OFF(path);        /* source path Offset               */
  146.   sregs.es = FP_SEG(fulypth);        /* target path Segment              */
  147.   regs.x.di = FP_OFF(fulypth);        /* target path Offset               */
  148.   ret=intdosx(®s,®s,&sregs);      /* DOS interrupt with 60h           */
  149.   setdisk(drivenb);            /* Old drive number                 */
  150.   if (regs.x.cflag!=0) return(ret);    /* Return code                      */
  151.   if (fulypth[1]!='\\') return(0);    /* if "\\servername\volume\path\.." */
  152.   for(i=0,j=2;fulypth[j]!='\\';j++);
  153.   for(j++;fulypth[j]!='\\';j++);
  154.   fulypth[i++]=drive[0];         /* Drive letter                     */
  155.   fulypth[i++]=':';            /* Colon                            */
  156.   fulypth[i++]='\\';            /* Backslash                        */
  157.   for(j++;fulypth[j]!='\0';)
  158.     fulypth[i++]=fulypth[j++];          /* copy path                        */
  159.   fulypth[i]='\0';
  160.   return(0);                /* no problem                       */
  161. }
  162.